package com.nineclock.document.controller;

import com.nineclock.common.entity.Result;
import com.nineclock.document.AppDocumentControllerApi;
import com.nineclock.document.dto.DocFileDto;
import com.nineclock.document.dto.DocFolderDto;
import com.nineclock.document.service.AppDocumentService;
import com.nineclock.document.dto.DocumentDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 黑马程序员
 * @Company http://www.ithiema.com
 * @Version 1.0
 */
@RestController
public class AppDocumentController  implements AppDocumentControllerApi{


    @Autowired
    AppDocumentService appDocumentService;

    @Override
    @GetMapping("/listFolderAndFile")
    public Result<DocumentDto> queryFolderAndFile(
            @RequestParam(value = "parentFoldId", required = false, defaultValue = "0") Long parentFolderId) {
        DocumentDto documentDto = appDocumentService.queryFolderAndFile(parentFolderId);
        return Result.success(documentDto);
    }

    @Override
    @PostMapping("/insertFolder")
    public Result insertFolder(@RequestBody DocFolderDto docFolderDto) {
        appDocumentService.insertFolder(docFolderDto);
        return Result.success();
    }

    @Override
    @PostMapping("/insertFile")
    public Result insertFile(@RequestBody DocFileDto docFileDto) {
        appDocumentService.insertFile(docFileDto);
        return Result.success();
    }

    @Override
    @GetMapping("/getFileByFileId")
    public Result<DocFileDto> getFileByFileId(@RequestParam("id") Long fileId) {
        DocFileDto docFileDto = appDocumentService.getFileByFileId(fileId);
        return Result.success(docFileDto);
    }
}
